<?php

	
	/**
	 * 用户注册控制器
	 * 用于用户注册了检查用户注册时是否存在
	 */
	 class RegisterController extends Controller{
	 	
		private $m = null;
		
		//初始用户UserModel
		public function __construct(){
			parent::__construct();
			$this->m = D('user');
		}
		
		
		
		/**
		 * 注册提交方法
		 */
		public function reg(){
			$post = array();
			$post['username'] = $_POST['username'];
			$post['passwd'] = md5($_POST['pwd']);
			$post['face'] = '/Images/noface.gif';
			$post['restime'] = time();
//			var_dump($post);
			if(!$_POST['username']){
				$this->error('请输入用户名','./index.php');
				die;
			}else if($_POST['pwd'] != $_POST['pwded']){
				$this->error('两次密码不一至','.index.php');
				die;
			}else if(strlen($_POST['username'])<2 || strlen($_POST['username']>12) ){
				$this->error('用户名必须是2-16个字符','./index.php');
				die;
			}else{
				if($this->m->register($post)>0)
					$this->success('注册成功','./index.php');
				}
							
		}
		
		/**
		 * 验证码显示方法
		 */
		public function code(){
			$code = new VerifyCode();
		}
		
		
		public function checkcode(){
			if($_POST['verify'] == session(C('SESSION_CODE'))){
				echo 1;
			}else{
				return false;
			}
		}
		
		/**
		 * 检测AJAX用户是否存在
		 */
		public function ajax_username($username=null){
			
			//判断用户是否存在
			$row = $this->m->checkuser($_POST['username']);
			if(empty($row)){
				echo 1;
			}else{
				return false;
			}
			
		}
		
	 }
	